﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Cofe.Core.Logger
{
    public class LoggerEventListener : IEventListener
    {
        [Export(typeof(ICofeService))]
        [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFE)]
        public class Factory : IEventListenerFactory
        {
            public void RegisterEventListener(IEventHub eventHub)
            {
                eventHub.RegisterEventListener(new LoggerEventListener());
            }
        }

        public void DispatchEvent(IEnumerable<IEventLog<EventArgs>> eventsRecorded)
        {
            foreach (var e in eventsRecorded)
            {
                string output = String.Format("{0} : {1}", e.UtcTime.ToShortTimeString(), e.EventArgs.ToString());
                CofeServices.Logger.Log(output, Category.Info, Priority.None);
            }                
        }

        public CancellationToken CancellationToken
        {
            get { return CancellationToken.None; }
        }

        public void Dispose()
        {            
        }
    }
}
